/*  代码来源【从0到1的点云】
 *  时间：2021.09.07
 * 功能：实现pcl的空间变化检测
 */
#include <iostream>
#include <pcl/point_cloud.h>
#include <pcl/octree/octree.h>
#include <vector>
#include <ctime>
void random_cloud(pcl::PointCloud<pcl::PointXYZ>::Ptr &cloud, int number)
{
	srand((unsigned int)time(NULL));
	(*cloud).height = 1;//random cloud flag
	(*cloud).width= number;
	(*cloud).points.resize(((*cloud).height)*((*cloud).width));
	for (size_t i = 0; i < (*cloud).points.size(); i++)
	{
		(*cloud).points[i].x = 64.0f*rand() / (RAND_MAX + 1.0F);
		(*cloud).points[i].y = 64.0f*rand() / (RAND_MAX + 1.0F);
		(*cloud).points[i].z = 64.0f*rand() / (RAND_MAX + 1.0F);
	}
}

int main()
{
	
	float resolution = 32.0f;
	pcl::octree::OctreePointCloudChangeDetector<pcl::PointXYZ> octree(resolution);
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloudA(new pcl::PointCloud<pcl::PointXYZ>);
	random_cloud(cloudA, 128);
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloudB(new pcl::PointCloud<pcl::PointXYZ>);
	random_cloud(cloudB, 5000);
	octree.setInputCloud(cloudA);
	octree.addPointsFromInputCloud();
	octree.switchBuffers();
	octree.setInputCloud(cloudB);
	octree.addPointsFromInputCloud();
	std::vector<int> new_point_index;
	octree.getPointIndicesFromNewVoxels(new_point_index);
	if (new_point_index.empty()!=0)
		std::cout << "vector no points!";

	return 0;
}